var mongoose = require('mongoose');
module.exports = mongoose.model('User', {
	username: {
		type: String,
		validate: {
			validator: function(v){
				//任意字母数字中文的组合
				return /^[a-zA-Z0-9\u4E00-\u9FA5]*$/.test(v);
			},
			message: "Invalid username",
			required: [true, 'username required']
		}
	},
	password: {
		type: String,
		validate: {
			validator: function(v){
				//字母开头，只能出现字母和数字，6-18位
				return /^[a-zA-Z]{1,}[a-zA-Z0-9]{5,17}$/.test(v);
			},
			message: "Invalid password",
			required: [true, 'password required']
		}
	},
	gender: {
		type: String,
		required: true
	},
	registerDate: {
		type: Date,
		default: Date.now
	},
	qq: {
		type: String,
		validate: {
			validator: function(v){
				//6-11位数字
				return /^[0-9]{6,11}$/.test(v);
			},
			message: "Invalid qq",
			required: [true, 'qq required']
		}
	},
	email: {
		type: String,
		validate: {
			validator: function(v){
				//xxx@xxx.xxx的形式
				return /^[a-zA-Z0-9]*@[a-zA-Z0-9]*.[a-zA-Z0-9]*$/.test(v);
			},
			message: "Invalid email",
			required: [true, 'email required']
		}
	}
});